# -*- coding: utf-8 -*-
"""
作者: 肖麒
联系方式：QQ：1505448035
时间: 2025/9/17 16:02
文件作用：
"""
import requests


class BilibiliCommentFetcher:
    """
    Bilibili评论获取器类

    用于从Bilibili平台获取视频评论数据的类，提供评论爬取和处理功能

    """

    def __init__(self):
        pass

    def get_BilibiliCommentFetcher(self):
        cookies = {
            'buvid4': 'C4B3BDF7-F27D-AF9E-F1D3-743CC5BE74EF44105-024052401-1WtluPXS6O1qAXM1ZqI9fA%3D%3D',
            'header_theme_version': 'CLOSE',
            'enable_web_push': 'DISABLE',
            'buvid_fp': '3500eb1405f6ce5cc6103bc46ce40bae',
            'LIVE_BUVID': 'AUTO3517424625703365',
            'enable_feed_channel': 'ENABLE',
            '_uuid': '7165B10210-105101-23102-2CE5-55CB5103B418F83830infoc',
            'hit-dyn-v2': '1',
            'buvid3': '16808DCE-CE77-1D97-B378-EFD2DC85DAE491162infoc',
            'b_nut': '1751249491',
            'DedeUserID': '183503735',
            'DedeUserID__ckMd5': 'c4deb1a2b7e85c15',
            'rpdid': "|(k||Yuklku)0J'u~luY))YJk",
            'theme-tip-show': 'SHOWED',
            'theme-avatar-tip-show': 'SHOWED',
            'PVID': '1',
            'theme-switch-show': 'SHOWED',
            'CURRENT_QUALITY': '64',
            'bili_ticket': 'eyJhbGciOiJIUzI1NiIsImtpZCI6InMwMyIsInR5cCI6IkpXVCJ9.eyJleHAiOjE3NTgxNjAyNjEsImlhdCI6MTc1NzkwMTAwMSwicGx0IjotMX0.l-OhXIAzNVuR4uFjy75RuIailFBZ4u_i1vCh37DWVrc',
            'bili_ticket_expires': '1758160201',
            'SESSDATA': '097a7cc3%2C1773453067%2Cc3381%2A91CjDA8YcT1I5auPLzSve_7PCHBl-JR9uo9lFeU5Ikfbmv5fBj9Ai5weZSLWICJWxt654SVkV0OUNFQUNVeno0NXVmaE9zZjZuNno3YnUtSkRaazJyU0ZRbENiTXRXM1lCc1UxTjR4b2NVaEVfSkNqY0plX1l6empuT0U5Y0pQVk81Tk9ackphYzVnIIEC',
            'bili_jct': 'a7ba8608224efb12de99be740d2ad945',
            'sid': '5eih2gh3',
            'home_feed_column': '5',
            'browser_resolution': '2552-1284',
            'b_lsid': '1087E582B_19956ADCB40',
            'bp_t_offset_183503735': '1113502294764158976',
            'CURRENT_FNVAL': '4048',
        }

        headers = {
            'accept': '*/*',
            'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
            'cache-control': 'no-cache',
            'origin': 'https://www.bilibili.com',
            'pragma': 'no-cache',
            'priority': 'u=1, i',
            'referer': 'https://www.bilibili.com/bangumi/play/ss28747?spm_id_from=333.337.0.0',
            'sec-ch-ua': '"Chromium";v="140", "Not=A?Brand";v="24", "Microsoft Edge";v="140"',
            'sec-ch-ua-mobile': '?0',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest': 'empty',
            'sec-fetch-mode': 'cors',
            'sec-fetch-site': 'same-site',
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36 Edg/140.0.0.0',
        }

        params = {
            'oid': '489733515',
            'type': '1',
            'mode': '3',
            'pagination_str': '{"offset":""}',
            'plat': '1',
            'seek_rpid': '',
            'web_location': '1315875',
            'w_rid': '2c4fd87a4c7a71ebae7a7ca4a1451860',
            'wts': '1758096012'
        }
        url = 'https://api.bilibili.com/x/v2/reply/wbi/main'

        response = requests.get(
            url,
            cookies=cookies,
            headers=headers,
            params=params,
        )

        print(response.text)

        json_data = response.json()
        data = json_data.get('data', '')
        replies = data.get('replies', '')

        comments = []
        for index, reply in enumerate(replies):
            message = reply.get('content', '').get('message', '')
            comments.append(message)
            print(f"评论 {index + 1}: {message}")
            print('---' * 50)

        return comments


# 使用示例
if __name__ == "__main__":
    fetcher = BilibiliCommentFetcher()
    fetcher.get_BilibiliCommentFetcher()
